<template>
  <van-datetime-picker
    v-model="currentDate"
    type="date"
    title="选择年月日"
    :min-date="minDate"
    :max-date="maxDate"
    @cancel="guanbi"
    @confirm="wancheng"
  />
</template>

<script>
import dayjs from '@/utils/day'
import { changeInfo } from '@/api'
export default {
  props: ['birthday'],
  data() {
    return {
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(),
      currentDate: new Date(this.birthday)
    }
  },
  methods: {
    guanbi() {
      this.$emit('chagesex')
    },
    async wancheng() {
      const a = dayjs(this.currentDate).format('YYYY-MM-DD')
      await changeInfo({
        birthday: a
      })
      //修改视图
      this.$emit('update:birthday', a)
      //关闭窗口
      this.$emit('chagesex')
    }
  }
}
</script>

<style></style>
